package domain.entities;

import org.hibernate.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Guillermo
 * Date: 17/10/12
 * Time: 10:32
 * To change this template use File | Settings | File Templates.
 */
public class ScorecardConfigurationDAO extends HibernateDaoSupport {

    private static final Logger log = LoggerFactory.getLogger(ScorecardConfigurationDAO.class);

    protected void initDao() {
        // do nothing
    }

    public List findByProperty(String propertyName, Object value) {
        log.debug("finding ScorecardConfiguration instance with property: " + propertyName
                + ", value: " + value);
        try {
            String queryString = "from ScorecardConfiguration as model where model."
                    + propertyName + "= ?";
            return getHibernateTemplate().find(queryString, value);
        } catch (RuntimeException re) {
            log.error("find by property name failed", re);
            throw re;
        }
    }


    public List findByCompromisopaisId(Integer compromisopaisId) {
        try {
            String queryString = "select s from ScorecardConfiguration s where s.compromisopais.id = " + compromisopaisId + " order by s.scorecardOrder asc";
            return getHibernateTemplate().find(queryString);
        } catch (RuntimeException re) {
            log.error("find all failed", re);
            throw re;
        }
    }

    public ScorecardConfiguration findById(java.lang.Integer id) {
        log.debug("getting ScorecardConfiguration instance with id: " + id);
        try {
            ScorecardConfiguration instance = (ScorecardConfiguration) getHibernateTemplate().get(
                    "domain.entities.ScorecardConfiguration", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }

}
